package cn.virens.common.boot.provider.apijson;

import apijson.orm.Visitor;
import cn.virens.common.boot.provider.auth.AuthUtil;
import cn.virens.common.util.exception.APIException;
import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class VirVisitor implements Visitor<String> {
    private final String tenant;
    private final String depart;
    private final String area;
    private final String role;
    private final String uuid;

    public VirVisitor() throws APIException {
        this.tenant = AuthUtil.getTenant();
        this.depart = AuthUtil.getDepart();
        this.area = AuthUtil.getArea();
        this.role = AuthUtil.getRole();
        this.uuid = AuthUtil.getUuid();
    }

    @Override
    public boolean equals(Object obj) throws APIException {
        return hashCode() == Objects.hashCode(uuid);
    }

    @Override
    public String toString() throws APIException {
        return JSON.toJSONString(this);
    }

    @Override
    public int hashCode() throws APIException {
        return Objects.hashCode(uuid);
    }

    @Override
    public List<String> getContactIdList() {
        return Arrays.asList(getId());
    }

    public String getTenant() {
        return tenant;
    }

    public String getDepart() {
        return depart;
    }

    public String getArea() {
        return area;
    }

    public String getRole() {
        return role;
    }

    public String getUuid() {
        return uuid;
    }

    @Override
    public String getId() {
        return uuid;
    }
}
